$.extend(planner.dialogs, {
    renameMech: {
        show: function()
        {
            $( "#dialog-rename-mech" ).dialog({
                height: 180,
                modal: true,
            });
        },
        rename_this_mech: function () {
            newname = $("#txtRenameThisMech").val()
            planner.garage.rename_mech(planner.garage.ui.selected_mech, newname);
            $( "#dialog-rename-mech" ).dialog("close");
        },
        ui:
        {
            setup: function()
            {
                
            },
            init: function()
            {
                $("#btnRenameThisMechCancel").button().click(
                    function () { 
                        $( "#dialog-rename-mech" ).dialog("close");                
                    }
                );
                
                $('#txtRenameThisMech').keypress(function(e) {
                    if (e.keyCode == $.ui.keyCode.ENTER) {
                        planner.dialogs.renameMech.rename_this_mech();
                    }
                });
                
                $(document).on("dialogopen", "#dialog-rename-mech", function(event, ui) {
                    setTimeout(function() {
                        $("#txtRenameThisMech").focus();    
                    },100);
                });

                $("#btnRenameThisMech").button().click( planner.dialogs.renameMech.rename_this_mech );
            },
        }
    }
});